﻿using Sport_Orders.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Sport_Orders.Program
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
        }

        // Вход пользователя
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            bool IsConnect = false;

            if (TxbLogin.Text != "" && PswPas.Password != "")
            {
                foreach (var record in Entities.GetContext().Admins)
                {
                    if (record.loginAdmin == TxbLogin.Text && record.passAdmin == PswPas.Password)
                    {
                        FirstWindow firstWindow = new FirstWindow(record.loginAdmin);
                        this.Close();
                        firstWindow.Show();
                        IsConnect = true;
                        break;
                    }
                }
                if (IsConnect == false)
                    MessageBox.Show("Неверный логин или пароль", "Ошибка", 
                                    MessageBoxButton.OK, 
                                    MessageBoxImage.Error);
            }
            else MessageBox.Show("Пустые поля", "Ошибка", 
                                 MessageBoxButton.OK, 
                                 MessageBoxImage.Error);
        }
    }
}
